package com.ssyt.yt1.day13;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

import com.ssyt.yt1.common.util.Util;

/**
 * 可视化日历
 * 
 * @author Administrator
 *
 */
public class VisualCalendarDemo {

	public static void main(String[] args) throws ParseException {
		// 用户输入的字符串
		String userInput = "2015-02-13";
		// 把用户输入的字符串转成Date
		Date date = Util.parse(userInput, "yyyy-MM-dd");
		// 再用Date得到Calendar
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
		int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

		// 改成1号
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

		System.out.println("日\t一\t二\t三\t四\t五\t六");
		// 打印空白
		for (int i = 1; i < dayOfWeek; i++) {
			System.out.print("\t");
		}
		// 打印日期
		for (int i = 1; i <= maxDay; i++) {
			if (calendar.get(Calendar.DAY_OF_MONTH) == currentDay) {
				System.out.print("*" + i + "\t");
			} else {
				System.out.print(i + "\t");
			}
			if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
				System.out.println();
			}
			calendar.add(Calendar.DAY_OF_WEEK, 1);
		}
	}
}
